/**
 * Created by Wilson on 1/23/2015.
 */
(function () {
    angular.module('app')
        .controller('seriesSelectorController', seriesSelectorController);

    seriesSelectorController.$inject = ['$scope', 'tunnelService', 'carService', 'alertController'];
    function seriesSelectorController($scope, tunnelService, carService, alertController) {
        $scope.toModelSelectorPage = toModelSelectorPage;

        $scope.getSeriesList = getSeriesList;

        getSeriesList();

        function getSeriesList() {
            var brandId = tunnelService.getData('brandSelector.brandId');
            carService.getSeriesListByBrandId(brandId).then(function (data) {
                $scope.seriesList = data.datas;
            }).catch(function (data) {
                alertController.simpleAlert(data.errMsg);
            });


        }

        function toModelSelectorPage(typeId, nameId) {
            tunnelService.setData('seriesSelector.typeId', typeId);
            tunnelService.setData('seriesSelector.nameId', nameId);
            $scope.ons.navigator.pushPage('pages/car/model-selector.html');
        }
    }

})();